package com.my.es.config;

import lombok.Data;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/5/11 10:38
 */
@ConfigurationProperties(prefix = "elasticsearch")
@Configuration
@Data
public class ESConfig extends AbstractElasticsearchConfiguration {
    
    @Value("${elasticsearch.host}")
    private String host;
    @Value("${elasticsearch.port}")
    private Integer port;


    @Override
    public RestHighLevelClient elasticsearchClient() {

        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost(host, port, "http")));
        return restHighLevelClient;

    }
}
